package com.example.test.accountinfoa.dao;

import com.example.test.accountinfoa.pojo.AccountInfo;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

@Repository
public interface AccountInfoDao extends JpaRepository<AccountInfo,Integer> {
    @Modifying
    @Query("update AccountInfo set accountBalance = accountBalance +?1 where accountNo=?2")
    void updateAccountBalance(Double amount, String accountNo);

    /**
     * 查询是否已经存在进行幂等操作
     * @param txNo
     * @return
     */
    @Query(value = "select coutn(1) from de_duplication where tx_no =?1" ,nativeQuery = true)
    int isExistTx(String txNo);


    /**
     * 向数据库中插入一条数据
     * @param txNo
     * @return
     */
    @Query(value = "inster into de_duplication values (?1,now())", nativeQuery = true)
    int addTx(String txNo);

}
